package com.plian.system.service.dwh.check;

import com.plian.system.bean.staff.*;
import com.plian.system.entity.dwh.DwhStaffManagement;
import com.plian.system.excel.ImportExcelUtil;
import com.plian.system.excel.ImportResult;
import com.plian.system.service.dwh.IDwhStaffManagementService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.List;

@AllArgsConstructor
public class DwhStaffManagementCheckDataSon {
    private IDwhStaffManagementService staffFilesService;
    private final static String OBJECT_MSG = "未找到对应对象!";
    /**
     * 任免记录子表检验
     */
    public static ImportResult checkAppointRemove(List<Object> readExcels, List<String>codeList, List<DwhStaffManagement> staffFilesList, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            AppointRemoveExcelBean appointRemoveExcelBean = (AppointRemoveExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;

            //判空
            msg.append(ImportExcelUtil.checkEmpty("4","人员编码",appointRemoveExcelBean.getDef1(),index).getMsg());
            //判断类型
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE,"4","会议决定日期",appointRemoveExcelBean.getMeetingDecisionDate(),index).getMsg());

//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(appointRemoveExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(appointRemoveExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("4",String.valueOf(index + 2),"人员编号",appointRemoveExcelBean.getDef1(),"不存在"));
//			}
        }
        //判重
        //对象和字典校验
        //统一放置报错
        if (msg.toString().length()>0) {
            importResult = new ImportResult(false, msg.toString());
        }
        return importResult;
    }

    /**
     * 本子表存在“参照”、“开关”
     * 学历学位子表校验
     */
    public static ImportResult checkEducationDegree(List<Object> readExcels, List<String>codeList, List<DwhStaffManagement> staffFilesList, HashMap<String, List<String>> codeMap, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            EducationDegreeExcelBean educationDegreeExcelBean = (EducationDegreeExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;

            //判空
            msg.append(ImportExcelUtil.checkEmpty("5","人员编码",educationDegreeExcelBean.getDef1(),index).getMsg());

            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE_MONTH,"5","开始时间",educationDegreeExcelBean.getStartDate(),index).getMsg());
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE_MONTH,"5","结束时间",educationDegreeExcelBean.getEndDate(),index).getMsg());
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER,"5","是否最高学位",educationDegreeExcelBean.getIsHighestDegree(),index).getMsg());
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER,"5","是否最高学历",educationDegreeExcelBean.getIsHighestEducational(),index).getMsg());
//
//
//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(educationDegreeExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(educationDegreeExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("5",String.valueOf(index + 2),"人员编号",educationDegreeExcelBean.getDef1(),"不存在"));
//			}
        }
        if (msg.toString().length() > 0) {
            return new ImportResult(false, msg.toString());
        }

        //对象、字典、开关校验
        for(Object readExcel:readExcels){
            EducationDegreeExcelBean educationDegreeExcelBean = (EducationDegreeExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);

            //教育类型
            if(StringUtils.isNotEmpty(educationDegreeExcelBean.getEducationTypeId()) && !codeMap.get("educationTypeRef").contains(educationDegreeExcelBean.getEducationTypeId())){
                msg.append(ImportExcelUtil.msgBuilder("5",String.valueOf(index + 2),"教育类型", educationDegreeExcelBean.getEducationTypeId(), OBJECT_MSG));
            }

            //学历
            if(StringUtils.isNotEmpty(educationDegreeExcelBean.getEducationalId()) && !codeMap.get("educationalRef").contains(educationDegreeExcelBean.getEducationalId())){
                msg.append(ImportExcelUtil.msgBuilder("5",String.valueOf(index + 2),"学历", educationDegreeExcelBean.getEducationalId(), OBJECT_MSG));
            }

            //学位
            if(StringUtils.isNotEmpty(educationDegreeExcelBean.getDegreeId()) && !codeMap.get("degreeRef").contains(educationDegreeExcelBean.getDegreeId())){
                msg.append(ImportExcelUtil.msgBuilder("5",String.valueOf(index + 2),"学位", educationDegreeExcelBean.getDegreeId(), OBJECT_MSG));
            }

            //开关
            msg.append(ImportExcelUtil.checkSwitch("5","是否最高学历",educationDegreeExcelBean.getIsHighestEducational(),index).getMsg());
            msg.append(ImportExcelUtil.checkSwitch("5","是否最高学位",educationDegreeExcelBean.getIsHighestDegree(),index).getMsg());
        }

        if (msg.toString().length() > 0) {
            return new ImportResult(false, msg.toString());
        }
        return importResult;
    }

    /**
     * 本子表存在“参照”
     * 工作经历子表校验
     */
    public static ImportResult checkWorkExperience(List<Object> readExcels,List<String>codeList, List<DwhStaffManagement> staffFilesList, HashMap<String, List<String>> codeMap, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            WorkExperienceExcelBean workExperienceExcelBean = (WorkExperienceExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;
            //判空
            msg.append(ImportExcelUtil.checkEmpty("6","人员编号",workExperienceExcelBean.getDef1(),index).getMsg());

            //判断类型
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE,"6","开始日期",workExperienceExcelBean.getStartDate(),index).getMsg());
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE,"6","结束日期",workExperienceExcelBean.getEndDate(),index).getMsg());

//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(workExperienceExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(workExperienceExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("6",String.valueOf(index + 2),"人员编号",workExperienceExcelBean.getDef1(),"不存在"));
//			}
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        //对象校验
        for(Object readExcel:readExcels){
            WorkExperienceExcelBean workExperienceExcelBean = (WorkExperienceExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);

            //职务名称
//			if(StringUtils.isNotEmpty(workExperienceExcelBean.getJobNameId()) && !codeMap.get("jobNameRef").contains(workExperienceExcelBean.getJobNameId())){
//				msg.append(ImportExcelUtil.msgBuilder("6",String.valueOf(index + 2),"职务名称", workExperienceExcelBean.getJobNameId(), OBJECT_MSG));
//			}
        }

        if (msg.toString().length() > 0) {
            return new ImportResult(false, msg.toString());
        }

        return importResult;
    }

    /**
     * 奖惩情况
     */
    public static ImportResult checkRewardsPunishments(List<Object> readExcels,List<String>codeList, List<DwhStaffManagement> staffFilesList, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            RewardsPunishmentsExcelBean rewardsPunishmentsExcelBean = (RewardsPunishmentsExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;
            //判空
            msg.append(ImportExcelUtil.checkEmpty("6","人员编号",rewardsPunishmentsExcelBean.getDef1(),index).getMsg());

            //判断类型
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE_MONTH,"6","奖励日期",rewardsPunishmentsExcelBean.getRewardDate(),index).getMsg());
//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(rewardsPunishmentsExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(rewardsPunishmentsExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("7",String.valueOf(index + 2),"人员编号",rewardsPunishmentsExcelBean.getDef1(),"不存在"));
//			}
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        return importResult;
    }

    /**
     * 年度考核结果
     */
    public static ImportResult checkAnnualAssessment(List<Object> readExcels,List<String>codeList, List<DwhStaffManagement> staffFilesList, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            AnnualAssessmentExcelBean annualAssessmentExcelBean = (AnnualAssessmentExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;
            //判空
            msg.append(ImportExcelUtil.checkEmpty("7","人员编号",annualAssessmentExcelBean.getDef1(),index).getMsg());
//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(annualAssessmentExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(annualAssessmentExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("8",String.valueOf(index + 2),"人员编号",annualAssessmentExcelBean.getDef1(),"不存在"));
//			}

        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        return importResult;
    }

    /**
     * 本子表存在“参照”
     * 家庭及社会关系
     */
    public static ImportResult checkSocialRelations(List<Object> readExcels,List<String>codeList, List<DwhStaffManagement> staffFilesList, HashMap<String, List<String>> codeMap, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            SocialRelationsExcelBean socialRelationsExcelBean = (SocialRelationsExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;
            //判空
            msg.append(ImportExcelUtil.checkEmpty("8","人员编号",socialRelationsExcelBean.getDef1(),index).getMsg());

            //类型
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE,"8","出生年月",socialRelationsExcelBean.getBirthday(),index).getMsg());
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER,"8","政治面貌",socialRelationsExcelBean.getPoliticCountenanceId(),index).getMsg());
//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(socialRelationsExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(socialRelationsExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("9",String.valueOf(index + 2),"人员编号",socialRelationsExcelBean.getDef1(),"不存在"));
//			}
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        //对象
        for(Object readExcel:readExcels){
            SocialRelationsExcelBean socialRelationsExcelBean = (SocialRelationsExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);

            //政治面貌
            if(StringUtils.isNotEmpty(socialRelationsExcelBean.getPoliticCountenanceId()) && !codeMap.get("politicCountenanceRef").contains(socialRelationsExcelBean.getPoliticCountenanceId())){
                msg.append(ImportExcelUtil.msgBuilder("8",String.valueOf(index + 2),"政治面貌", socialRelationsExcelBean.getPoliticCountenanceId(), OBJECT_MSG));
            }
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        return importResult;
    }

    /**
     * 从业资格证书
     */
    public static ImportResult checkPractitionerCertificate(List<Object> readExcels,List<String>codeList, List<DwhStaffManagement> staffFilesList, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            PractitionerCertificateExcelBean practitionerCertificateExcelBean = (PractitionerCertificateExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;
            //判空
            msg.append(ImportExcelUtil.checkEmpty("9","人员编号",practitionerCertificateExcelBean.getDef1(),index).getMsg());

            //类型
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE_MONTH,"9","取得日期",practitionerCertificateExcelBean.getBuildDate(),index).getMsg());
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE_MONTH,"9","有效日期",practitionerCertificateExcelBean.getEffectiveTime(),index).getMsg());

//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(practitionerCertificateExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(practitionerCertificateExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("10",String.valueOf(index + 2),"人员编号",practitionerCertificateExcelBean.getDef1(),"不存在"));
//			}
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        return importResult;
    }

    /**
     * 本子表存在“参照”
     * 专业技术资格
     */
    public static ImportResult checkTechnicalQualification(List<Object> readExcels,List<String>codeList, List<DwhStaffManagement> staffFilesList, HashMap<String, List<String>> codeMap, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            TechnicalQualificationExcelBean technicalQualificationExcelBean = (TechnicalQualificationExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;
            //判空
            msg.append(ImportExcelUtil.checkEmpty("10","人员编号",technicalQualificationExcelBean.getDef1(),index).getMsg());

            //类型
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER,"10","专业技术职称级别",technicalQualificationExcelBean.getTechnicalTitleLevelId(),index).getMsg());
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE_MONTH,"10","取得日期",technicalQualificationExcelBean.getBuildDate(),index).getMsg());
//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(technicalQualificationExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(technicalQualificationExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("11",String.valueOf(index + 2),"人员编号",technicalQualificationExcelBean.getDef1(),"不存在"));
//			}
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        //对象校验
        for(Object readExcel:readExcels){
            TechnicalQualificationExcelBean technicalQualificationExcelBean = (TechnicalQualificationExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);

            //专业技术职称级别
            if(StringUtils.isNotEmpty(technicalQualificationExcelBean.getTechnicalTitleLevelId()) && !codeMap.get("technicalTitleLevelRef").contains(technicalQualificationExcelBean.getTechnicalTitleLevelId())){
                msg.append(ImportExcelUtil.msgBuilder("10",String.valueOf(index + 2),"专业技术职称级别", technicalQualificationExcelBean.getTechnicalTitleLevelId(), OBJECT_MSG));
            }
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        return importResult;
    }

    /**
     * 近五年三个月以上培训情况
     */
    public static ImportResult checkTrain(List<Object> readExcels,List<String>codeList, List<DwhStaffManagement> staffFilesList, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            TrainExcelBean trainExcelBean = (TrainExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;

            //判空
            msg.append(ImportExcelUtil.checkEmpty("11","人员编号",trainExcelBean.getDef1(),index).getMsg());

            //类型
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE_MONTH,"11","开始时间",trainExcelBean.getStartTime(),index).getMsg());
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_DATE_MONTH,"11","结束时间",trainExcelBean.getEndTime(),index).getMsg());
//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(trainExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(trainExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("12",String.valueOf(index + 2),"人员编号",trainExcelBean.getDef1(),"不存在"));
//			}
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        return importResult;
    }

    /**
     * 侨眷情况
     */
    public static ImportResult checkOverseasMembers(List<Object> readExcels,List<String>codeList, List<DwhStaffManagement> staffFilesList, HashMap<String, List<String>> codeMap, Boolean isCover){
        ImportResult importResult = new ImportResult(true,"");
        StringBuilder msg = new StringBuilder();
        for(Object readExcel:readExcels){
            OverseasMembersExcelBean overseasMembersExcelBean = (OverseasMembersExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            int flag = 0;
            //判空
            msg.append(ImportExcelUtil.checkEmpty("12","人员编号",overseasMembersExcelBean.getDef1(),index).getMsg());

            //对象
            msg.append(ImportExcelUtil.checkType(ImportExcelUtil.TYPE_INTEGER,"12","性别",overseasMembersExcelBean.getOverseasSex(),index).getMsg());
//			if(!isCover) {
//				//Excel
//				for (String code : codeList) {
//					if (code.equals(overseasMembersExcelBean.getDef1())) {
//						//如果主表编号存在
//						flag = 1;
//						break;
//					}
//				}
//			}
//			//数据库
//			for(StaffFiles staffFiles:staffFilesList){
//				if(staffFiles.getStaffCode().equals(overseasMembersExcelBean.getDef1())){
//					//如果主表编号存在
//					flag = 1;
//					break;
//				}
//			}
//			if(flag == 0){
//				msg.append(ImportExcelUtil.msgBuilder("13",String.valueOf(index + 2),"人员编号",overseasMembersExcelBean.getDef1(),"不存在"));
//			}
        }
        if(msg.toString().length()>0){
            return new ImportResult(false,msg.toString());
        }
        //对象和字典是否存在校验
        for(Object readExcel : readExcels){
            OverseasMembersExcelBean overseasMembersExcelBean = (OverseasMembersExcelBean)readExcel;
            int index = readExcels.indexOf(readExcel);
            //性别
            if(StringUtils.isNotEmpty(overseasMembersExcelBean.getOverseasSex()) && !codeMap.get("genderRef").contains(overseasMembersExcelBean.getOverseasSex())){
                msg.append(ImportExcelUtil.msgBuilder("12",String.valueOf(index + 2),"性别", overseasMembersExcelBean.getOverseasSex(), OBJECT_MSG));
            }
        }
        if (msg.toString().length()>0) {
            importResult = new ImportResult(false, msg.toString());
        }
        return importResult;
    }
}
